package com.liu.service;

import com.alibaba.fastjson.JSONObject;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Hystix服务降级。作用对象是消费端。
 */
@Component
public class UsersClientServiceFallbackFactory implements FallbackFactory {

    @Override
    public Object create(Throwable throwable) {
        return new UsersClientService() {
            @Override
            public void addUsers(JSONObject param) {

            }

            @Override
            public void delUsers(String userId) {

            }

            @Override
            public void modifyUsers(JSONObject param) {

            }

            @Override
            public JSONObject queryUsersCount(String usersString) {
                JSONObject result = new JSONObject();
                result.put("resultCode", "-1");
                result.put("resultDesc", "failed");
                result.put("resultData", new JSONObject());
                return result;
            }

            @Override
            public JSONObject queryUsers(String usersString) {
                JSONObject result = new JSONObject();
                result.put("resultCode", "-1");
                result.put("resultDesc", "服务已经被关闭，消费端对服务进行降级");
                result.put("resultData", new JSONObject());
                return result;
            }
        };
    }
}
